import React from 'react';
import { connect } from 'dva'
import { Card, Divider,Table } from 'antd';
import DescriptionList from 'components/DescriptionList';
import PageHeaderLayout from 'components/Layout/PageHeaderLayout';
import { LwjTable } from "components";
import moment from 'moment';
import { receiptStatus } from "utils/enumConfig"
import { LwjDownload } from 'components'
import { receiptType } from 'utils/enumConfig'

const { Description } = DescriptionList;

const handleLogsColumns = [
  {
    title: '操作时间',
    dataIndex: 'handleTime',
    key: 'handleTime',
    width: "10%",
    render: (text, record, index) => (moment(record.handleTime).format("YYYY-MM-DD HH:mm:ss"))
  },
  {
    title: '操作人',
    dataIndex: 'handlerName',
    key: 'handlerName',
    width: "10%",
  },
  {
    title: '操作类型',
    dataIndex: 'handleType',
    key: 'handleType',
    width: "10%",
    render: (text, record, index) => (receiptStatus[text])
  },
];
const offsetsColumns = [
  {
    title: '结算单据编号',
    dataIndex: 'orderNum',
    key: 'orderNum',
    width: "10%",
  },
  {
    title: '冲抵日期',
    dataIndex: 'createTime',
    key: 'createTime',
    width: "10%",
    render: (text, record, index) => (moment(record.createTime).format("YYYY-MM-DD HH:mm:ss"))
  },
  {
    title: '结算总金额(元)',
    dataIndex: 'batchMoney',
    key: 'batchMoney',
    width: "10%",
    render: (text, record, index) => (record.batchMoney.toFixed(2))
  },
  {
    title: '冲抵金额(元)',
    dataIndex: 'offset',
    key: 'offset',
    width: "10%",
    render: (text, record, index) => (record.offset.toFixed(2))
  },
  {
    title: '操作人',
    dataIndex: 'handlerName',
    key: 'handlerName',
    width: "10%",
  }
];


const receiptDetails = ({ location, dispatch, receiptDetail, loading }) => {

  const { currentItemDetail, test } = receiptDetail;

  const breadcrumbList = [
    {
      title: '财务管理',
    }, {
      title: '收款单',
      href: '/receipt'
    }, {
      title: '收款单详情',
    }
  ];

  return (
    <PageHeaderLayout title="收款单详情页" breadcrumbList={breadcrumbList}>
      {!_.isEmpty(currentItemDetail) && <Card bordered={false}>
        <DescriptionList
          size="large"
          title="收款单信息"
          style={{
            marginBottom: 32
          }}>

          <Description term="收款单号">{currentItemDetail.num}</Description>
          <Description term="收款单类型">{receiptType[currentItemDetail.receiptType]}</Description>
          <Description term="收款方">{currentItemDetail.receipterName}</Description>
          <Description term="收款账户">{currentItemDetail.receipterAccount}</Description>
          <Description term="付款方">{currentItemDetail.paymenterName}</Description>
          <Description term="支付方式">{currentItemDetail.paymentType === "alipay_pc_direct" ? "线上充值(支付宝)" : currentItemDetail.paymentType === "wx_pub_qr" ? "线上充值(微信)" : currentItemDetail.paymentType}</Description>
          <Description term="支付时间">{moment(currentItemDetail.paymentTime).format("YYYY-MM-DD HH:mm:ss")}</Description>
          {currentItemDetail.arrivalTime && <Description term="到账时间">{moment(currentItemDetail.arrivalTime).format("YYYY-MM-DD HH:mm:ss")}</Description>}
          <Description term="支付凭证号">{currentItemDetail.paymentNum}</Description>
          <Description term="应收金额">{currentItemDetail.receivable}</Description>
          <Description term="实收金额">{currentItemDetail.received}</Description>
          <Description term="制单人">{currentItemDetail.creatorName}</Description>
          <Description term="手续费">{currentItemDetail.serviceFee}</Description>
          {/* <Description term="结算号">{currentItemDetail.settlementNum}</Description> */}
          <Description term="备注">{currentItemDetail.memo}</Description>
          <Description term="附件"><LwjDownload title={'点击下载'} targetUrl={currentItemDetail.attachments || ''}/></Description>
        </DescriptionList>
        <Divider style={{
          marginBottom: 32
        }} />
        <DescriptionList
          size="large"
          title="审核信息"
          style={{
            marginBottom: 30
          }}>
          <Description term="审核人">{currentItemDetail.auditorName}</Description>
          <Description term="审核时间">{currentItemDetail.auditTime > 0 ? moment(currentItemDetail.auditTime).format("YYYY-MM-DD HH:mm:ss") : ""}</Description>
          <Description term="审核结果">{currentItemDetail.auditStatus === "NULL" ? "待审核" : currentItemDetail.auditStatus === "AUDIT_SUCCESS" ? "审核通过" : "审核未通过"}</Description>
          <Description term="备注">{currentItemDetail.auditRemark}</Description>
        </DescriptionList>
        <Divider style={{
          marginBottom: 32
        }} />
        <div>冲抵记录</div>
        <LwjTable pagination={false} dataSource={currentItemDetail.offsetSummaries} columns={offsetsColumns}  />
        <Divider style={{
          marginBottom: 32
        }} />
        <div>操作记录</div>
        <LwjTable pagination={false} dataSource={currentItemDetail.handleLogs} columns={handleLogsColumns}/>
      </Card>}
    </PageHeaderLayout>
  )
};


export default connect(({ receiptDetail, loading }) => ({ receiptDetail, loading }))(receiptDetails)
